package com.hdhere.core.rest;

import java.util.HashMap;
import java.util.Map;

public class ErrorObject {

    /**
     * 错误代码
     */
    public static enum ErrorCode {
        PARAM_ERROR("参数错误"), PERMISSION_ERROR("权限错误"), LOGIN_REDIRECT_ERROR("登录成功重定向错误"), QUERY_ERROR("查询出错"), SERVER_ERROR(
                "服务器异常"), NOT_FOUND("未找到"), PWD_ERROR("密码错误"), OPERATION_EXCEPTION("操作异常"), LOGIN_ERROR("未登录错误");

        private String name;

        private ErrorCode(String name) {

            this.name = name;
        }

        public String toString() {

            return name;
        }

        public String value() {

            return name;
        }
    };

    public static Map<String, Object> error(ErrorCode errorCode, String message) {

        return error(errorCode, message, null);
    }

    public static Map<String, Object> error(ErrorCode errorCode, String message, Object data) {

        Map<String, Object> result = new HashMap<String, Object>();
        result.put("status", "error");
        result.put("errorCode", errorCode);
        result.put("message", message);
        result.put("data", data);
        return result;
    }
}
